Displaying Frames
As explained earlier, a Java program displays graphical output in virtual windows called frames. Since frames correspond to Mac OS windows, you can manipulate them in a similar manner (for example, create or destroy frames, resize them, and so on).In order to communicate between the abstract frames and the actual Mac OS windows, you must designate a number of application-defined callback functions. Many of these functions correspond to similar Mac OS Toolbox functions. The application-defined functions and their corresponding Mac OS Toolbox functions are shown in Table 1-1. For details of the structure of these functions, see "Application-Defined Functions" (page 97).
Table 1-1 Application-defined frame functions Frame function Description Corresponding Mac OS Toolbox function MyRequestFrame
Creates a new window GetNewCWindow
,NewCWindow
,GetNewWindow
, orNewWindow
MyReleaseFrame
Disposes of a window DisposeWindow
MySetUpPort
Sets up a graphics port GetPort(&gSave)
andSetPort
MyRestorePort
Restores a graphics port SetPort(gSave)
MyResizeRequest
Requests that a window be resized SizeWindow
MyInvalRect
Invalidates a portion of a window InvalRect
MyShowHide
Shows or hides a window ShowHide
orShowWindow and HideWindow
MySetTitle
Sets the window title bar SetWTitle
MyCheckUpdate
Checks to see if a window update is necessary CheckUpdate or BeginUpdate
andEndUpdate
Typically the bulk of an application-defined frame function is spent preparing a call to the corresponding Mac OS Toolbox function. For example, assuming that the application uses the functions in Listing 1-7 (page 16) and Listing 1-8 (page 17), you can use the callback function in Listing 1-9 to set the window title.
Listing 1-9 A callback function to change the title of a window
void MySetTitle(JMFrameRef frame, Str255 title) { WindowPtr win = getFrameWindow(frame); if (win) SetWTitle(win, title); }